﻿using System;
using System.Configuration;
using System.Data;

namespace EXAM.UserControl
{
    public partial class ucGarget : System.Web.UI.UserControl
    {
        string _width = "298px";
        int _heigth = 128;

        public int Heigth
        {
            get { return _heigth; }
            set { _heigth = value; }
        }
        string _title = "Title";
        DataTable _datasource;
        string _DefaultLink = "";
        public DataTable Datasource
        {
            get { return _datasource; }
            set
            {
                _datasource = value;
                //LoadDataSource(_datasource);
            }
        }
        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }
        public string DefaultLink
        {
            get { return _DefaultLink; }
            set { _DefaultLink = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDataSource(_datasource);
            }
        }

        public void LoadDataSource(DataTable dt)
        {
            if (lbItems != null)
            {
                Panel1.Height = Heigth;
                string result = "";
                foreach (DataRow row in dt.Rows)
                {
                    string tmp = "  <li>" +
                          "<a class=\"active\" href=\"{0}\" target=\"{2}\" onclick=\"{3}\">" +
                         " <span class=\"l\"></span><span class=\"r\">" +
                        "  </span><span class=\"t\" style='float:left;'>{1}</span> {4}</a>" +

                        "  </li>";
                    string isNew = "";
                    
                    DTO.GadgetItemsInfo inf = new DTO.GadgetItemsInfo(row);
                    if (inf.IsNew == "T")
                        isNew = "<img src='images/new.png'  style='float:right;'/>";
                    string constr = "";
                    if (inf.Link == "")
                    {
                        inf.Link = "#";
                        constr = "ShowMsg('"+ConfigurationSettings.AppSettings["NoneDocument"]+"')";
                    }

                    result += String.Format(tmp, "LearnLog.aspx?id=" + inf.ID, inf.Name, inf.Target, constr, isNew);
                }

                lbItems.Text = result;
            }
        }
        public string Width
        {
            get
            {
                return _width;
            }
            set
            {
                _width = value;
            }
        }
    }
}